from rich.live import Live
from rich.panel import Panel
from rich.console import Console
import random
import time

console = Console()

with Live(auto_refresh=False) as live:
    while True:
        # 生成随机数据
        cpu = random.randint(0, 100)
        mem = random.randint(0, 100)
        data = f"CPU: [bold red]{cpu}%[/bold red] | MEM: [bold blue]{mem}%[/bold blue]"
        
        # 创建动态面板
        panel = Panel(
            data,
            title="系统监控",
            border_style="bright_magenta",
            padding=(1, 2)
        )
        live.update(panel, refresh=True)
        time.sleep(1)